package com.qf.smsplatfrom.controller;

import com.github.pagehelper.PageInfo;
import com.qf.smsplatfrom.dto.R;
import com.qf.smsplatfrom.mapper.NotifyMapper;
import com.qf.smsplatfrom.pojo.TNotify;
import com.qf.smsplatfrom.service.NotifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/notify")
public class NotifyController {
    private NotifyService notifyService;
    @Autowired
    public void setNotifyService(NotifyService notifyService) {
        this.notifyService = notifyService;
    }

    @PostMapping("/notify")
    public R addNotify(@RequestBody TNotify tNotify){
        notifyService.addNotify(tNotify);
        return R.setOk();
    }
    @PutMapping("/notify")
    public R updateNotify(@RequestBody TNotify tNotify){
        notifyService.updateNotify(tNotify);
        return R.setOk();
    }
    @GetMapping("/notify")
    public R showAllNotify(@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "5") Integer pageSize){
        PageInfo<TNotify> pageInfo = notifyService.showAllNotify(pageNum, pageSize);
        return R.setOk(pageInfo);
    }
    @DeleteMapping("/notify")
    public R deleteNotify(@RequestBody Map map){
        notifyService.removeNotify(((List<Integer>) map.get("ids")));
        return R.setOk();
    }

}
